package myAsm;

import java.util.Map;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Transient;

import org.objectweb.asm.MethodVisitor;

@Entity
@DiscriminatorValue("INSN_FIELD")
public class MyFieldInsnNode extends MyAbstractInsnNode {

	public MyFieldInsnNode() {
		super(-1);
	}
	
    /**
     * The internal name of the field's owner class (see
     * {@link org.objectweb.asm.Type#getInternalName() getInternalName}).
     */
	@Column(name="FIELDINSN_OWNER")
    public String owner;

    /**
     * The field's name.
     */
	@Column(name="FIELDINSN_NAME")
    public String name;

    /**
     * The field's descriptor (see {@link org.objectweb.asm.Type}).
     */
	@Column(name="FIELDINSN_DESC")
    public String desc;
	
    /**
     * Constructs a new {@link FieldInsnNode}.
     * 
     * @param opcode the opcode of the type instruction to be constructed. This
     *        opcode must be GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
     * @param owner the internal name of the field's owner class (see
     *        {@link org.objectweb.asm.Type#getInternalName() getInternalName}).
     * @param name the field's name.
     * @param desc the field's descriptor (see {@link org.objectweb.asm.Type}).
     */
	public MyFieldInsnNode(
			int opcode,
			final String owner,
	        final String name,
	        final String desc) {
		super(opcode);
		this.owner = owner;
        this.name = name;
        this.desc = desc;
	}

	 /**
     * Sets the opcode of this instruction.
     * 
     * @param opcode the new instruction opcode. This opcode must be GETSTATIC,
     *        PUTSTATIC, GETFIELD or PUTFIELD.
     */
    public void setOpcode(final int opcode) {
        this.opcode = opcode;
    }
	
	@Override
	public int getType() {
		return FIELD_INSN;
	}

	@Override
	public void accept(MethodVisitor cv) {
		cv.visitFieldInsn(opcode, owner, name, desc);
	}

	@Override
	public MyAbstractInsnNode clone(Map labels) {
		 return new MyFieldInsnNode(opcode, owner, name, desc);
	}

}
